package org.clockworkmages.games.anno1186.generator.sets;

import org.clockworkmages.games.anno1186.dao.GameObjectsList;
import org.clockworkmages.games.anno1186.generator.GameObjectGenerator;
import org.clockworkmages.games.anno1186.model.character.SkillConstants;
import org.clockworkmages.games.anno1186.model.character.StatConstants;
import org.clockworkmages.games.anno1186.model.effect.Effect;
import org.clockworkmages.games.anno1186.model.option.GenericOption;
import org.clockworkmages.games.anno1186.model.situation.GenericSituation;
import org.clockworkmages.games.anno1186.scripting.tools.EffectBuilder;
import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder;

public class PalosJuan
		extends GameObjectGenerator
//
		implements StatConstants, SkillConstants, TechnicalSituationConstants {

	public String getFileName() {
		return "palos_juan";
	}

	@Override
	public GameObjectsList generate() {
		GameObjectsList gameObjects = new GameObjectsList();

		GenericOption option = new GenericOption();
		GenericSituation situation = new GenericSituation();

		// located options:
		option = new GenericOption();
		option.setSituationId("PALOS_TAVERN");
		option.setSee("captain Juan de la Cosa");
		option.setLabel("Juan de la Cosa");
		option.setIcon("talk");
		option.setCondition(ScriptBuilder.NEW().not().plot()
				.is("PALOS_JOINED_THE_CREW").toString());
		option.setGoToSituation("PALOS_TAVERN_JUAN");
		option.setAddToStack(true);
		gameObjects.getOptions().add(option);

		// located options:
		option = new GenericOption();
		option.setSituationId("PALOS_DOCKS");
		option.setSee("Santa Maria - the ship that you signed up to");
		option.setLabel("come aboard Santa Maria");
		option.setIcon("in");
		option.setCondition(ScriptBuilder.NEW().plot()
				.is("PALOS_JOINED_THE_CREW").and().not().util().isNight()
				.toString());
		option.setAddToStack(false);
		gameObjects.getOptions().add(option);

		// Situations:
		situation = new GenericSituation();
		situation.setClearScreen(true);
		situation.setId("PALOS_TAVERN_JUAN");
		situation.setText("As you were finishing your supper...");
		gameObjects.getSituations().add(situation);

		option = new GenericOption();
		option.setLabel("Expedition");
		option.setTooltip("'Tell me more about that expedition of yours'");
		option.getEffects().add(
				new Effect("situation.addState('ASKED_ABOUT_EXPEDITION')"));
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition("situation.hasState('ASKED_ABOUT_EXPEDITION')");
		option.setLabel("Crew");
		option.setTooltip("'Who's on your crew?'");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition("situation.hasState('ASKED_ABOUT_EXPEDITION')");
		option.setLabel("Uncharted territories");
		option.setTooltip("'Unknown land beyond the ocean, seriously?'");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition("situation.hasState('ASKED_ABOUT_EXPEDITION')");
		option.getEffects().add(
				new Effect("situation.addState('ASKED_ABOUT_PROFIT')"));
		option.setLabel("Profit");
		option.setTooltip("'How much would I earn if I joined you?'");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition("situation.hasState('ASKED_ABOUT_PROFIT')"
				+ " && !situation.hasState('BARGAINED')" + " && "
				+ ScriptBuilder.ME().skillRoll(SPEECH, -10).toString());
		option.getEffects()
				.add(new Effect("plot.set('PALOS_JOINED_THE_CREW')"));
		option.getEffects().add(EffectBuilder.me().addGold(50).compileEffect());
		option.setGoToSituation("PALOS_TAVERN_JUAN_AGREE");
		option.setLabel("Agreed, but I want 50 coins paid in advance! (Speech, "
				+ ScriptBuilder.ME().skillChance(SPEECH, -10).asPlaceholder()
				+ "%)");
		option.setTextAfter("The captains assesses you with his stare in silence for a longer moment.\n"
				+ " - All right then, ${if me.male}lad{$else}lass${fi} - he says eventually - I don't normally do that, but I'm in desperate need of men, and you look like you look resourceful. Here's your gold, just be sure you'll be in the docks thing in the morning. We sail out at noon!");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setOr(true);
		option.setCondition("situation.hasState('ASKED_ABOUT_PROFIT') && !situation.hasState('BARGAINED')");
		option.getEffects().add(new Effect("situation.addState('BARGAINED')"));
		option.setLabel("Agreed, but I want 50 coins paid in advance! (Speech, Reputation, "
				+ ScriptBuilder.ME().skillChance(SPEECH, -10).asPlaceholder()
				+ "%)");
		option.setTextAfter(" - Sorry ${if me.isMale()}lad${else}lass${fi}, but that is not an option. - says the captain - But you'll get your money once we're back, every copper of it, you have my word.");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setGoToSituation("PALOS_TAVERN_JUAN_AGREE");
		option.getEffects()
				.add(new Effect("plot.set('PALOS_JOINED_THE_CREW')"));
		option.setLabel("Great! Where do I sign?");
		option.setTextAfter(" - Splendid! - exclaims the captain - Make sure you'll be in the docks in the morning - we sail out at noon! You won't regret it my friend, it's going to be a once-in-a-lifetime adveture, you'll see!");

		situation.getOptions().add(option);

		option = new GenericOption();
		option.setGoToSituation(ST_EMPTY_RETURN);
		option.setLabel("I need to think about it");
		option.setTextAfter(" - Well don't think too long, it's a once-in-a lifetime opportunity! - says the captain - But sure, take your time. I'll be around here a bit longer.");
		situation.getOptions().add(option);

		//
		situation = new GenericSituation();
		situation.setClearScreen(false);
		situation.setId("PALOS_TAVERN_JUAN_AGREE");
		situation
				.setText(" - Now, it's getting late and I need to be going back to my place to get some sleep. I'd advice that you do the same, ${if me.male}lad{$else}lass${fi}. It's going to be a busy day tomorrow.");
		situation
				.setText("The captains gets up from his chair and walks towards the door.");
		gameObjects.getSituations().add(situation);

		option = new GenericOption();
		option.setGoToSituation("EMPTY_RETURN");
		option.setLabel("I'll see you in the morning!");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition(ScriptBuilder.ME().getSkillLevel(STEALTH).gt(0)
				.and().me().skillRoll(STEALTH, -10).toString());
		option.getEffects().add(EffectBuilder.me().addGold(50).compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		option.setLabel("Pickpocket him as he passes you! (Stealth, "
				+ ScriptBuilder.ME().skillChance(STEALTH, -10).asPlaceholder()
				+ "%)");
		option.setTextAfter("[Success!] You quickly steal the captain's purse without the old man noticing anything.");
		situation.getOptions().add(option);

		option = new GenericOption();
		option.setCondition(ScriptBuilder.ME().getSkillLevel(STEALTH).gt(0)
				.toString());
		option.setOr(true);
		option.setGoToSituation(ST_EMPTY_RETURN);
		option.setLabel("Pickpocket him as he passes you! (Stealth, Agility, "
				+ ScriptBuilder.ME().skillChance(STEALTH, -10).asPlaceholder()
				+ "%)");
		option.setTextAfter("[Fail] With so many people in the inn it's not easy to find the right moment to steal the captain's purse unnoticed, and the old seaman leaves the tavern before you could make your move.");
		situation.getOptions().add(option);

		return gameObjects;
	}

}
